<?php
    require('./Utils.php');

    $post = getJsonParamter();

    $username = $post['username'];
    $order_number = $post['order_number'];

    $conn = getConnection();
    $sql = "SELECT order_id, status, date, image, name, price, pet_number
            FROM user u LEFT JOIN `order` o
            ON u.username = o.user_id
            LEFT JOIN pet_order po
            ON o.id = po.order_id
            LEFT JOIN pet p
            ON p.id = po.pet_id
            WHERE o.id = ? AND u.username= ?";

    $res = query_list($conn, $sql, $order_number, $username);

    $data = array();
    $data['pet_list'] = array();

    foreach($res as $r){
        $pet_list = array();

        $pet_list['image'] = $r['image'];
        $pet_list['name'] = $r['name'];
        $pet_list['price'] = $r['price'];
        $pet_list['number'] = $r['pet_number'];

        $data['order_number'] = $r['order_id'];
        $data['date'] = $r['date'];
        $data['status'] = $r['status'];
        $data['totalPrice'] += $r['price'] * $r['pet_number'];

        array_push($data['pet_list'], $pet_list);
    }

    getJson(200, '获取成功', $data);

?>